<?php

use think\migration\Migrator;
use think\migration\db\Column;

class CreateUserToken extends Migrator
{
    public function up()
    {
        $table = $this->table('user_token',['signed' => false,'comment'=>'用户token表']);
        $table->addColumn('user_id','integer',['limit'=>10,'comment'=>'用户Id'])
            ->addForeignKey('user_id', 'user', 'id', ['delete'=> 'CASCADE'])
            ->addColumn('token','string',['limit'=>120,'comment'=>'调用api的唯一凭证token'])
            ->addIndex('token',['unique' => true])
            ->addColumn('token_expire_time','integer',['default'=>0,'limit'=>10,'comment'=>'token过期时间'])
            ->addColumn('union_id','string',['default'=>'','limit'=>120,'comment'=>'微信unionId'])
            ->addColumn('create_time','integer',['limit'=>10,'default'=>0,'comment'=>'创建时间'])
            ->addColumn('update_time','integer',['limit'=>10,'default'=>0,'comment'=>'更新时间'])
            ->save();
    }
    public function down()
    {
        $this->dropTable('user_token');
    }
}
